package com.mapull.simple;

/**
 * @author mapull
 */
public class Array {

    private int[] data;

    private int size;

    public Array(int capacity){
        data = new int[capacity];
        size = 0;
    }

    public Array(){
        this(10);
    }

    public int getSize() {
        return size;
    }

    public int getCapacity(){
        return data.length;
    }

    public boolean isEmpty(){
        return size == 0;
    }

    public void addLast(int i){
        if(size == data.length){
            throw new IllegalArgumentException("Add failed");
        }
        data[size] = i;
        size++;
    }

    public void add(int index, int num){
        if(size == data.length){
            throw new IllegalArgumentException("Add failed");
        }
        if(index < 0 || index > size){
            throw new IllegalArgumentException("Add failed");
        }
        for(int i = size -1; i> index ; i--){
            data[i + 1]  = data[i];
        }
        data[index] = num;
        size ++;
    }
}
